package forum.dao.memory;

import forum.entities.Category;
import forum.dao.CategoryDAO;

import java.math.BigInteger;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class MemoryCategoryDAO extends MemoryGenericDAO<Category> implements CategoryDAO {
    @Override
    public List<Category> findCategoriesByParentCategoryId(BigInteger parentCategoryId) {
        Iterator<Category> it = getEntitiesIterator();
        LinkedList<Category> foundCategories = new LinkedList<Category>();
        while(it.hasNext()) {
            Category record = it.next();
            if (record.getParentCategoryId().equals(parentCategoryId)) {
                foundCategories.add(record);
            }
        }
        return foundCategories;
    }

    @Override
    protected Category newEntity() {
        return new Category(getNewKey());
    }

    @Override
    public Category getRootCategory() {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
